﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Nightlife.Models;
using System.Web.Security;

namespace Nightlife.Controllers
{
    public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }

        public ActionResult Feed()
        {
            User user = DB.GetUser(Membership.GetUser());

            if (user == null)
                return View();

            List<Checkin> checkins = new List<Checkin>();

            foreach (User friend in user.Friends)
            {
                List<Checkin> temp = DB.GetCheckins(friend);
                foreach (Checkin checkin in temp)
                    checkins.Add(checkin);
            }
            checkins = checkins.OrderByDescending(u => u.Created).ToList();
            return View(checkins);
        }
    }
}
